package com.tuozixuan.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.tuozixuan.dao.UserDao;
import com.tuozixuan.entity.User;
import com.tuozixuan.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	private final UserDao userDao;
	
	public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }
	
	public User getUserById(Long id) {
		return userDao.getOne(id);
        //return userDao.getById(id);
    }
	
	public List<User> listUser() {
        return userDao.findAll();
    }

    public Long save(User user) {
        userDao.save(user);
        return user.getId();
    }

    public Long update(Long id, User user) {
        // 有id则更新，无id则新增
        user.setId(id);
        userDao.save(user);
        return id;
    }

    public Long delete(Long id) {
        User user = new User();
        user.setId(id);
        userDao.delete(user);
        return id;
    }

}
